home *** CD-ROM | disk | FTP | other *** search
- {****************************************************}
- { CCharGrid.p}
- {}
- { The CharGrid Class}
- {}
- { A grid where each item is a character from a single font. Since}
- { fonts are just bitmaps, a font editor can be used to create one}
- { where each "character" is really a small picture. This is how a}
- { palette of tools is typically implemented.}
- {}
- { SUPERCLASS = CGridSelector}
- {}
- { Copyright ⌐ 1989, Symantec Corporation. All rights reserved. }
- {}
- {****************************************************}
-
- unit CCharGrid;
-
- interface
-
- uses
- TCL, MoreTCL;
-
- type
-
- ChGdRec = record { Resource template for a char grid }
- rows: integer;
- cols: integer;
- boxWidth: integer;
- boxHeight: integer;
- hSizing: integer;
- vSizing: integer;
- hLoc: integer;
- vLoc: integer;
- commandBase: integer;
- theSize: integer;
- extra: packed array[0..511] of char; {"Extra" contains two }
- {pascal strings: the font name }
- {followed by the characters. }
- end;
-
- ChGdPtr = ^ChGdRec;
- ChGdHand = ^ChGdPtr;
-
-
- implementation
-
-
- {****************************************************}
- { ICharGrid}
- {}
- { Initialize a CharGrid object}
- {}
- {****************************************************}
-
- procedure CCharGrid.ICharGrid (ChGdid: integer; anEnclosure: CView; aSupervisor: CBureaucrat);
- var
- r: ChGdHand;
- p: ChGdPtr;
- aTextInfo: TextInfoRec;
- i: integer;
- fontName: Str255;
- theEnvironment: CEnvironment; { Altered by TCL Weaver 1.0 (5/9/90) }
-
- begin
- r := ChGdHand(GetResource('ChGd', ChGdid));
- CheckResource(Handle(r));
- HLock(Handle(r));
- p := r^;
-
- IGridSelector(anEnclosure, aSupervisor, p^.hLoc, p^.vLoc, SizingOption(p^.hSizing), SizingOption(p^.vSizing), 1, p^.commandBase, p^.rows, p^.cols, p^.boxWidth, p^.boxHeight);
-
- aTextInfo.theSize := p^.theSize;
- aTextInfo.theStyle := [];
- aTextInfo.theMode := srcOr;
-
- BlockMove(@p^.extra[0], @fontName, ord(p^.extra[0]) + 1);
- GetFontNumber(fontName, aTextInfo.fontNumber);
-
- i := ord(p^.extra[ord(p^.extra[0]) + 1]);
- theCharacters := ChGdArrayH(NewHandle(i));
- BlockMove(@p^.extra[ord(p^.extra[0]) + 2], @theCharacters^^, ord(p^.extra[ord(p^.extra[0]) + 1]));
-
- HUnlock(Handle(r));
-
- new(CTextEnvirons(theEnvironment)); { Altered by TCL Weaver 1.0 (5/9/90) }
- itsEnvironment := theEnvironment;
- CTextEnvirons(itsEnvironment).SetTextInfo(aTextInfo);
- end;
-
-
- {****************************************************}
- { Free (OVERRIDE)}
- {}
- { Dispose of a character grid}
- {}
- {****************************************************}
-
- procedure CCharGrid.Free;
- begin
- DisposHandle(Handle(theCharacters)); {Get rid of list of characters }
- inherited Free; { Pass message on to superclass }
- end;
-
-
- {****************************************************}
- { DrawItem (OVERRIDE)}
- {}
- { Draw the character at the specified row and column}
- {}
- {****************************************************}
-
- procedure CCharGrid.DrawItem (theItem: integer; theBox: Rect);
- var
- fInfo: FontInfo; { Info about the font }
- theChar: char;
-
- begin
- GetFontInfo(fInfo);
- theChar := theCharacters^^[theItem - 1];
- MoveTo(theBox.left + (boxWidth - CharWidth(theChar)) div 2, theBox.bottom - (boxHeight - fInfo.ascent - fInfo.descent) div 2);
- DrawChar(theChar);
- end;
-
-
- end.